package com.zmn.plat.admin.controller.service.itemdetail;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.admin.controller.PlatBaseController;
import com.zmn.plat.business.interfaces.service.item.ServiceItemBService;
import com.zmn.plat.model.vo.warranty.WarrantyInfoVO;
import com.zmn.plat.services.interfaces.category.BaseCategoryService;
import com.zmn.plat.services.interfaces.company.BaseCompanyService;
import com.zmn.plat.services.interfaces.servcategory.ServCategoryService;
import com.zmn.plat.services.interfaces.service.group.ServiceGroupService;
import com.zmn.plat.services.interfaces.service.item.ServiceItemService;
import com.zmn.plat.services.interfaces.service.item.servicetime.ServServiceTimeService;
import com.zmn.plat.services.interfaces.service.tariff.ServiceTariffService;
import com.zmn.plat.services.interfaces.warranty.content.WarrantyContentService;
import com.zmn.plat.services.interfaces.warranty.info.WarrantyInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

/**
 * 故障分组项目表
 *
 * @author tanbiao
 * @since 2019-11-21 18:57:24
 */
public class ServiceItemDetailBaseController extends PlatBaseController {
    protected Logger logger = LoggerFactory.getLogger(this.getClass());
    @Resource
    protected ServiceItemService faultItemService;
    @Resource
    protected ServiceItemBService faultItemBService;
    @Resource
    protected WarrantyInfoService warrantyInfoService;
    @Resource
    protected WarrantyContentService warrantyContentService;
    @Resource
    protected ServiceGroupService faultGroupService;
    @Resource
    protected ServiceTariffService faultTariffService;
    @Resource
    protected BaseCategoryService baseCategoryService;
    @Resource
    protected ServCategoryService servCategoryService;
    @Resource
    protected BaseCompanyService companyService;
    @Resource
    protected ServServiceTimeService serviceTimeService;

    void ListSort(List<WarrantyInfoVO> list) {
        { // 排序方法
            Collections.sort(list, new Comparator<WarrantyInfoVO>() {
                @Override
                public int compare(WarrantyInfoVO o1, WarrantyInfoVO o2) {
                    SimpleDateFormat format = new SimpleDateFormat(DateUtil.FORMAT_DEFAULT);
                    try {
                        // format.format(o1.getTime()) 表示 date转string类型 如果是string类型就不要转换了
                        Date dt1 = format.parse(format.format(o1.getUpdateTime()));
                        Date dt2 = format.parse(format.format(o2.getUpdateTime()));
                        // 这是由大向小排序 如果要由小向大转换比较符号就可以
                        if (dt1.getTime() < dt2.getTime()) {
                            return 1;
                        } else if (dt1.getTime() > dt2.getTime()) {
                            return -1;
                        } else {
                            return 0;
                        }
                    } catch (Exception e) {

                    }
                    return 0;
                }

            });
        }
    }
}
